<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en"><head><title>URI Template</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="description" content="URI Template">
<meta name="generator" content="xml2rfc v1.36 (http://xml.resource.org/)">
<style type='text/css'><!--
        body {
                font-family: verdana, charcoal, helvetica, arial, sans-serif;
                font-size: small; color: #000; background-color: #FFF;
                margin: 2em;
        }
        h1, h2, h3, h4, h5, h6 {
                font-family: helvetica, monaco, "MS Sans Serif", arial, sans-serif;
                font-weight: bold; font-style: normal;
        }
        h1 { color: #900; background-color: transparent; text-align: right; }
        h3 { color: #333; background-color: transparent; }

        td.RFCbug {
                font-size: x-small; text-decoration: none;
                width: 30px; height: 30px; padding-top: 2px;
                text-align: justify; vertical-align: middle;
                background-color: #000;
        }
        td.RFCbug span.RFC {
                font-family: monaco, charcoal, geneva, "MS Sans Serif", helvetica, verdana, sans-serif;
                font-weight: bold; color: #666;
        }
        td.RFCbug span.hotText {
                font-family: charcoal, monaco, geneva, "MS Sans Serif", helvetica, verdana, sans-serif;
                font-weight: normal; text-align: center; color: #FFF;
        }

        table.TOCbug { width: 30px; height: 15px; }
        td.TOCbug {
                text-align: center; width: 30px; height: 15px;
                color: #FFF; background-color: #900;
        }
        td.TOCbug a {
                font-family: monaco, charcoal, geneva, "MS Sans Serif", helvetica, sans-serif;
                font-weight: bold; font-size: x-small; text-decoration: none;
                color: #FFF; background-color: transparent;
        }

        td.header {
                font-family: arial, helvetica, sans-serif; font-size: x-small;
                vertical-align: top; width: 33%;
                color: #FFF; background-color: #666;
        }
        td.author { font-weight: bold; font-size: x-small; margin-left: 4em; }
        td.author-text { font-size: x-small; }

        /* info code from SantaKlauss at http://www.madaboutstyle.com/tooltip2.html */
        a.info {
                /* This is the key. */
                position: relative;
                z-index: 24;
                text-decoration: none;
        }
        a.info:hover {
                z-index: 25;
                color: #FFF; background-color: #900;
        }
        a.info span { display: none; }
        a.info:hover span.info {
                /* The span will display just on :hover state. */
                display: block;
                position: absolute;
                font-size: smaller;
                top: 2em; left: -5em; width: 15em;
                padding: 2px; border: 1px solid #333;
                color: #900; background-color: #EEE;
                text-align: left;
        }

        a { font-weight: bold; }
        a:link    { color: #900; background-color: transparent; }
        a:visited { color: #633; background-color: transparent; }
        a:active  { color: #633; background-color: transparent; }

        p { margin-left: 2em; margin-right: 2em; }
        p.copyright { font-size: x-small; }
        p.toc { font-size: small; font-weight: bold; margin-left: 3em; }
        table.toc { margin: 0 0 0 3em; padding: 0; border: 0; vertical-align: text-top; }
        td.toc { font-size: small; font-weight: bold; vertical-align: text-top; }

        ol.text { margin-left: 2em; margin-right: 2em; }
        ul.text { margin-left: 2em; margin-right: 2em; }
        li      { margin-left: 3em; }

        /* RFC-2629 <spanx>s and <artwork>s. */
        em     { font-style: italic; }
        strong { font-weight: bold; }
        dfn    { font-weight: bold; font-style: normal; }
        cite   { font-weight: normal; font-style: normal; }
        tt     { color: #036; }
        tt, pre, pre dfn, pre em, pre cite, pre span {
                font-family: "Courier New", Courier, monospace; font-size: small;
        }
        pre {
                text-align: left; padding: 4px;
                color: #000; background-color: #CCC;
        }
        pre dfn  { color: #900; }
        pre em   { color: #66F; background-color: #FFC; font-weight: normal; }
        pre .key { color: #33C; font-weight: bold; }
        pre .id  { color: #900; }
        pre .str { color: #000; background-color: #CFF; }
        pre .val { color: #066; }
        pre .rep { color: #909; }
        pre .oth { color: #000; background-color: #FCF; }
        pre .err { background-color: #FCC; }

        /* RFC-2629 <texttable>s. */
        table.all, table.full, table.headers, table.none {
                font-size: small; text-align: center; border-width: 2px;
                vertical-align: top; border-collapse: collapse;
        }
        table.all, table.full { border-style: solid; border-color: black; }
        table.headers, table.none { border-style: none; }
        th {
                font-weight: bold; border-color: black;
                border-width: 2px 2px 3px 2px;
        }
        table.all th, table.full th { border-style: solid; }
        table.headers th { border-style: none none solid none; }
        table.none th { border-style: none; }
        table.all td {
                border-style: solid; border-color: #333;
                border-width: 1px 2px;
        }
        table.full td, table.headers td, table.none td { border-style: none; }

        hr { height: 1px; }
        hr.insert {
                width: 80%; border-style: none; border-width: 0;
                color: #CCC; background-color: #CCC;
        }
--></style>
</head>
<body>
<table summary="layout" cellpadding="0" cellspacing="2" class="TOCbug" align="right"><tr><td class="TOCbug"><a href="#toc">&nbsp;TOC&nbsp;</a></td></tr></table>
<table summary="layout" width="66%" border="0" cellpadding="0" cellspacing="0"><tr><td><table summary="layout" width="100%" border="0" cellpadding="2" cellspacing="1">
<tr><td class="header">Network Working Group</td><td class="header">J. Gregorio</td></tr>
<tr><td class="header">Internet-Draft</td><td class="header">Google</td></tr>
<tr><td class="header">Intended status: Standards Track</td><td class="header">R. Fielding</td></tr>
<tr><td class="header">Expires: March 29, 2012</td><td class="header">Adobe</td></tr>
<tr><td class="header">&nbsp;</td><td class="header">M. Hadley</td></tr>
<tr><td class="header">&nbsp;</td><td class="header">MITRE</td></tr>
<tr><td class="header">&nbsp;</td><td class="header">M. Nottingham</td></tr>
<tr><td class="header">&nbsp;</td><td class="header">Rackspace</td></tr>
<tr><td class="header">&nbsp;</td><td class="header">D. Orchard</td></tr>
<tr><td class="header">&nbsp;</td><td class="header">Salesforce.com</td></tr>
<tr><td class="header">&nbsp;</td><td class="header">Sep 26, 2011</td></tr>
</table></td></tr></table>
<h1><br />URI Template<br />draft-gregorio-uritemplate-07</h1>

<h3>Abstract</h3>

<p>
    A URI Template is a compact sequence of characters
    for describing a range of Uniform Resource Identifiers
    through variable expansion.
    This specification defines the URI Template
    syntax and the process for expanding a URI Template into a
    URI reference, along with guidelines for the
    use of URI Templates on the Internet.
   
</p>
<h3>Editorial Note (to be removed by RFC Editor)</h3>

<p>
    To provide feedback on this Internet-Draft, join the
    <a href='http://lists.w3.org/Archives/Public/uri/'>W3C URI
    mailing list (http://lists.w3.org/Archives/Public/uri/)</a>.
   
</p>
<h3>Status of this Memo</h3>
<p>
This Internet-Draft is submitted  in full
conformance with the provisions of BCP&nbsp;78 and BCP&nbsp;79.</p>
<p>
Internet-Drafts are working documents of the Internet Engineering
Task Force (IETF).  Note that other groups may also distribute
working documents as Internet-Drafts.  The list of current
Internet-Drafts is at http://datatracker.ietf.org/drafts/current/.</p>
<p>
Internet-Drafts are draft documents valid for a maximum of six months
and may be updated, replaced, or obsoleted by other documents at any time.
It is inappropriate to use Internet-Drafts as reference material or to cite
them other than as &ldquo;work in progress.&rdquo;</p>
<p>
This Internet-Draft will expire on March 29, 2012.</p>

<h3>Copyright Notice</h3>
<p>
Copyright (c) 2011 IETF Trust and the persons identified as the
document authors.  All rights reserved.</p>
<p>
This document is subject to BCP 78 and the IETF Trust's Legal
Provisions Relating to IETF Documents
(http://trustee.ietf.org/license-info) in effect on the date of
publication of this document.  Please review these documents
carefully, as they describe your rights and restrictions with respect
to this document. Code Components extracted from this document must
include Simplified BSD License text as described in Section 4.e of
the Trust Legal Provisions and are provided without warranty as
described in the Simplified BSD License.</p>
<a name="toc"></a><br /><hr />
<h3>Table of Contents</h3>
<p class="toc">
<a href="#intro">1.</a>&nbsp;
Introduction<br />
&nbsp;&nbsp;&nbsp;&nbsp;<a href="#overview">1.1.</a>&nbsp;
Overview<br />
&nbsp;&nbsp;&nbsp;&nbsp;<a href="#types">1.2.</a>&nbsp;
Levels and Expression Types<br />
&nbsp;&nbsp;&nbsp;&nbsp;<a href="#design">1.3.</a>&nbsp;
Design Considerations<br />
&nbsp;&nbsp;&nbsp;&nbsp;<a href="#limitations">1.4.</a>&nbsp;
Limitations<br />
&nbsp;&nbsp;&nbsp;&nbsp;<a href="#notation">1.5.</a>&nbsp;
Notational Conventions<br />
&nbsp;&nbsp;&nbsp;&nbsp;<a href="#unicode-normal">1.6.</a>&nbsp;
Character Encoding and Unicode Normalization<br />
<a href="#syntax">2.</a>&nbsp;
Syntax<br />
&nbsp;&nbsp;&nbsp;&nbsp;<a href="#literals">2.1.</a>&nbsp;
Literals<br />
&nbsp;&nbsp;&nbsp;&nbsp;<a href="#expressions">2.2.</a>&nbsp;
Expressions<br />
&nbsp;&nbsp;&nbsp;&nbsp;<a href="#variables">2.3.</a>&nbsp;
Variables<br />
&nbsp;&nbsp;&nbsp;&nbsp;<a href="#modifiers">2.4.</a>&nbsp;
Value Modifiers<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="#prefix-values">2.4.1.</a>&nbsp;
Prefix Values<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="#composite-values">2.4.2.</a>&nbsp;
Composite Values<br />
<a href="#expansion">3.</a>&nbsp;
Expansion<br />
&nbsp;&nbsp;&nbsp;&nbsp;<a href="#literal-expansion">3.1.</a>&nbsp;
Literal Expansion<br />
&nbsp;&nbsp;&nbsp;&nbsp;<a href="#expression-expansion">3.2.</a>&nbsp;
Expression Expansion<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="#variable-expansion">3.2.1.</a>&nbsp;
Variable Expansion<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="#op-simple">3.2.2.</a>&nbsp;
Simple String Expansion: {var}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="#op-plus">3.2.3.</a>&nbsp;
Reserved expansion: {+var}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="#op-crosshatch">3.2.4.</a>&nbsp;
Fragment expansion: {#var}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="#op-dot">3.2.5.</a>&nbsp;
Label expansion with dot-prefix: {.var}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="#op-slash">3.2.6.</a>&nbsp;
Path segment expansion: {/var}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="#op-semicolon">3.2.7.</a>&nbsp;
Path-style parameter expansion: {;var}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="#op-question">3.2.8.</a>&nbsp;
Form-style query expansion: {?var}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="#op-ampersand">3.2.9.</a>&nbsp;
Form-style query continuation: {&amp;var}<br />
<a href="#anchor1">4.</a>&nbsp;
Security Considerations<br />
<a href="#iana">5.</a>&nbsp;
IANA Considerations<br />
<a href="#ack">6.</a>&nbsp;
Acknowledgments<br />
<a href="#rfc.references1">7.</a>&nbsp;
Normative References<br />
<a href="#implementation">Appendix&nbsp;A.</a>&nbsp;
Implementation Hints<br />
<a href="#rfc.authors">&#167;</a>&nbsp;
Authors' Addresses<br />
</p>
<br clear="all" />

<a name="intro"></a><br /><hr />
<table summary="layout" cellpadding="0" cellspacing="2" class="TOCbug" align="right"><tr><td class="TOCbug"><a href="#toc">&nbsp;TOC&nbsp;</a></td></tr></table>
<a name="rfc.section.1"></a><h3>1.&nbsp;
Introduction</h3>

<a name="overview"></a><br /><hr />
<table summary="layout" cellpadding="0" cellspacing="2" class="TOCbug" align="right"><tr><td class="TOCbug"><a href="#toc">&nbsp;TOC&nbsp;</a></td></tr></table>
<a name="rfc.section.1.1"></a><h3>1.1.&nbsp;
Overview</h3>

<p>
     A Uniform Resource Identifier (URI) <a class='info' href='#RFC3986'>[RFC3986]<span> (</span><span class='info'>Berners-Lee, T., Fielding, R., and L. Masinter, &ldquo;Uniform Resource Identifier (URI): Generic Syntax,&rdquo; January&nbsp;2005.</span><span>)</span></a>
     is often used to identify a specific resource within a common
     space of similar resources. For example, personal web spaces
     are often delegated using a common pattern, such as
    
</p><div style='display: table; width: 0; margin-left: 3em; margin-right: auto'><pre>
  http://example.com/~fred/
  http://example.com/~mark/
</pre></div>
<p>
     or a set of dictionary entries might be grouped in a hierarchy
     by the first letter of the term, as in
    
</p><div style='display: table; width: 0; margin-left: 3em; margin-right: auto'><pre>
  http://example.com/dictionary/c/cat
  http://example.com/dictionary/d/dog
</pre></div>
<p>
     or a service interface might be invoked with various user input
     in a common pattern, as in
    
</p><div style='display: table; width: 0; margin-left: 3em; margin-right: auto'><pre>
  http://example.com/search?q=cat&amp;lang=en
  http://example.com/search?q=chien&amp;lang=fr
</pre></div>
<p>
     URI Templates provide a mechanism for abstracting a space of
     resource identifiers such that the variable parts can be easily
     identified and described.  URI templates can have many uses,
     including discovery of available services, configuring resource
     mappings, defining computed links, specifying interfaces, and
     other forms of programmatic interaction with resources.
     For example, the above resources could be described by the
     following URI templates:
    
</p><div style='display: table; width: 0; margin-left: 3em; margin-right: auto'><pre>
  http://example.com/~{username}/
  http://example.com/dictionary/{term:1}/{term}
  http://example.com/search{?q,lang}
</pre></div>
<p>
     We define the following terms:
     </p>
<ul class="text">
<li>expression -
         The text between '{' and '}', including the enclosing braces,
         as defined in <a class='info' href='#syntax'>Section&nbsp;2<span> (</span><span class='info'>Syntax</span><span>)</span></a>.
</li>
<li>expansion -
         The string result obtained from a template expression after
         processing it according to its expression type, list of variable
         names, and value modifiers, as defined in <a class='info' href='#expansion'>Section&nbsp;3<span> (</span><span class='info'>Expansion</span><span>)</span></a>.
</li>
<li>template processor -
         A program or library that, given a URI Template and a set of
         variables with values, transforms the template string into a
         URI-reference by parsing the template for expressions and
         substituting each one with its corresponding expansion.
</li>
</ul><p>
     
</p>
<p>
     A URI Template provides both a structural description of a URI
     space and, when variable values are provided, machine-readable
     instructions on how to construct a URI corresponding to those values.
     A URI Template is transformed into a URI-reference by replacing each
     delimited expression with its value as defined by the
     expression type and the values of variables named within the
     expression.  The expression types range from simple string
     expansion to multiple name=value lists.  The expansions
     are based on the URI generic syntax, allowing an implementation
     to process any URI Template without knowing the scheme-specific
     requirements of every possible resulting URI.
    
</p>
<p>
     For example, the following URI Template includes a
     form-style parameter expression, as indicated by the "?" operator
     appearing before the variable names.
    
</p><div style='display: table; width: 0; margin-left: 3em; margin-right: auto'><pre>
  http://www.example.com/foo{?query,number}
</pre></div>
<p>
     The expansion process for expressions beginning with the
     question-mark ("?") operator follows the same pattern
     as form-style interfaces on the World Wide Web:
    
</p><div style='display: table; width: 0; margin-left: 3em; margin-right: auto'><pre>
  http://www.example.com/foo{?query,number}
                            \_____________/
                               |
                               |
          For each defined variable in [ 'query', 'number' ],
          substitute "?" if it is the first substitution or "&amp;"
          thereafter, followed by the variable name, '=', and the
          variable's value.
</pre></div>
<p>
     If the variables have the values
    
</p><div style='display: table; width: 0; margin-left: 3em; margin-right: auto'><pre>
  query  := "mycelium"
  number := 100
</pre></div>
<p>
     then the expansion of the above URI Template is
    
</p><div style='display: table; width: 0; margin-left: 3em; margin-right: auto'><pre>
  http://www.example.com/foo?query=mycelium&amp;number=100
</pre></div>
<p>
     Alternatively, if 'query' is undefined, then the expansion
     would be
    
</p><div style='display: table; width: 0; margin-left: 3em; margin-right: auto'><pre>
  http://www.example.com/foo?number=100
</pre></div>
<p>
     or if both variables are undefined, then it would be
    
</p><div style='display: table; width: 0; margin-left: 3em; margin-right: auto'><pre>
  http://www.example.com/foo
</pre></div>
<p>
     A URI Template may be provided in absolute form, as in the examples
     above, or in relative form.  A template MUST be expanded before the
     resulting reference can be resolved from relative to absolute form.
    
</p>
<p>
     Although the URI syntax is used for the result, the template
     string is allowed to contain the broader set of characters
     that can be found in IRI references <a class='info' href='#RFC3987'>[RFC3987]<span> (</span><span class='info'>Duerst, M. and M. Suignard, &ldquo;Internationalized Resource Identifiers (IRIs),&rdquo; January&nbsp;2005.</span><span>)</span></a>.
     A URI Template is therefore also an IRI template, and the result
     of template processing can be transformed to an IRI by following
     the process defined in Section 3.2 of <a class='info' href='#RFC3987'>[RFC3987]<span> (</span><span class='info'>Duerst, M. and M. Suignard, &ldquo;Internationalized Resource Identifiers (IRIs),&rdquo; January&nbsp;2005.</span><span>)</span></a>.
    
</p>
<a name="types"></a><br /><hr />
<table summary="layout" cellpadding="0" cellspacing="2" class="TOCbug" align="right"><tr><td class="TOCbug"><a href="#toc">&nbsp;TOC&nbsp;</a></td></tr></table>
<a name="rfc.section.1.2"></a><h3>1.2.&nbsp;
Levels and Expression Types</h3>

<p>
     URI Templates are similar to a macro language with a fixed set of
     macro definitions: the expression type determines the expansion
     process.  The default expression type is simple string expansion, wherein
     a single named variable is replaced by its value as a string after UTF-8
     encoding the characters and then pct-encoding any octets that are
     not in the unreserved set.
    
</p>
<p>     
     Since most template processors implemented prior to this specification
     have only implemented the default expression type, we refer to these as
     Level 1 templates.
    
</p><div style='display: table; width: 0; margin-left: 3em; margin-right: auto'><pre>
.-----------------------------------------------------------------.
| Level 1 examples, with variables having values of               |
|                                                                 |
|             var   := "value"                                    |
|             hello := "Hello World!"                             |
|                                                                 |
|-----------------------------------------------------------------|
| Op       Expression            Expansion                        |
|-----------------------------------------------------------------|
|     | Simple string expansion                       (Sec 3.2.2) |
|     |                                                           |
|     |    {var}                 value                            |
|     |    {hello}               Hello%20World%21                 |
`-----------------------------------------------------------------'
</pre></div>
<p>     
     Level 2 templates add the plus ("+") operator, for expansion of
     values that are allowed to include reserved characters, and the
     crosshatch ("#") operator for expansion of fragment identifiers.  
    
</p><div style='display: table; width: 0; margin-left: 3em; margin-right: auto'><pre>
.-----------------------------------------------------------------.
| Level 2 examples, with variables having values of               |
|                                                                 |
|             var   := "value"                                    |
|             hello := "Hello World!"                             |
|             path  := "/foo/bar"                                 |
|                                                                 |
|-----------------------------------------------------------------|
| Op       Expression            Expansion                        |
|-----------------------------------------------------------------|
|  +  | Reserved string expansion                     (Sec 3.2.3) |
|     |                                                           |
|     |    {+var}                value                            |
|     |    {+hello}              Hello%20World!                   |
|     |    {+path}/here          /foo/bar/here                    |
|     |    here?ref={+path}      here?ref=/foo/bar                |
|-----+-----------------------------------------------------------|
|  #  | Fragment expansion, crosshatch-prefixed       (Sec 3.2.4) |
|     |                                                           |
|     |    X{#var}               X#value                          |
|     |    X{#hello}             X#Hello%20World!                 |
`-----------------------------------------------------------------'
</pre></div>
<p>     
     Level 3 templates add more complex operators for lists of
     comma-separated values, dot-prefixed labels, slash-prefixed path
     segments, semicolon-prefixed path parameters, and the forms-style
     construction of a query syntax consisting of name=value pairs that
     are separated by an ampersand character.  
    
</p><div style='display: table; width: 0; margin-left: 3em; margin-right: auto'><pre>
.-----------------------------------------------------------------.
| Level 3 examples, with variables having values of               |
|                                                                 |
|             var   := "value"                                    |
|             hello := "Hello World!"                             |
|             empty := ""                                         |
|             path  := "/foo/bar"                                 |
|             x     := "1024"                                     |
|             y     := "768"                                      |
|                                                                 |
|-----------------------------------------------------------------|
| Op       Expression            Expansion                        |
|-----------------------------------------------------------------|
|     | String expansion with multiple variables      (Sec 3.2.2) |
|     |                                                           |
|     |    map?{x,y}             map?1024,768                     |
|     |    {x,hello,y}           1024,Hello%20World%21,768        |
|     |                                                           |
|-----+-----------------------------------------------------------|
|  +  | Reserved expansion with multiple variables    (Sec 3.2.3) |
|     |                                                           |
|     |    {+x,hello,y}          1024,Hello%20World!,768          |
|     |    {+path,x}/here        /foo/bar,1024/here               |
|     |                                                           |
|-----+-----------------------------------------------------------|
|  #  | Fragment expansion with multiple variables    (Sec 3.2.4) |
|     |                                                           |
|     |    {#x,hello,y}          #1024,Hello%20World!,768         |
|     |    {#path,x}/here        #/foo/bar,1024/here              |
|     |                                                           |
|-----+-----------------------------------------------------------|
|  .  | Label expansion, dot-prefixed                 (Sec 3.2.5) |
|     |                                                           |
|     |    X{.var}               X.value                          |
|     |    X{.x,y}               X.1024.768                       |
|     |                                                           |
|-----+-----------------------------------------------------------|
|  /  | Path segments, slash-prefixed                 (Sec 3.2.6) |
|     |                                                           |
|     |    {/var}                /value                           |
|     |    {/var,x}/here         /value/1024/here                 |
|     |                                                           |
|-----+-----------------------------------------------------------|
|  ;  | Path-style parameters, semicolon-prefixed     (Sec 3.2.7) |
|     |                                                           |
|     |    {;x,y}                ;x=1024;y=768                    |
|     |    {;x,y,empty}          ;x=1024;y=768;empty              |
|     |                                                           |
|-----+-----------------------------------------------------------|
|  ?  | Form-style query, ampersand-separated         (Sec 3.2.8) |
|     |                                                           |
|     |    {?x,y}                ?x=1024&amp;y=768                    |
|     |    {?x,y,empty}          ?x=1024&amp;y=768&amp;empty=             |
|     |                                                           |
|-----+-----------------------------------------------------------|
|  &amp;  | Form-style query continuation                 (Sec 3.2.9) |
|     |                                                           |
|     |    ?fixed=yes{&amp;x}        ?fixed=yes&amp;x=1024                |
|     |    {&amp;x,y,empty}          &amp;x=1024&amp;y=768&amp;empty=             |
|     |                                                           |
`-----------------------------------------------------------------'
</pre></div>
<p>     
     Finally, Level 4 templates add the ability to specify value modifiers
     as a suffix to the variable name.  The prefix modifier (":") indicates
     that only a limited number of characters from the beginning of the
     value are used by the expansion.  The explode ("*") modifier indicates
     that the variable is to be treated as a composite value, consisting of
     either a list of names or an associative array of (name, value) pairs,
     that is expanded as if each member were a separate variable.
    
</p><div style='display: table; width: 0; margin-left: 3em; margin-right: auto'><pre>
.-----------------------------------------------------------------.
| Level 4 examples, with variables having values of               |
|                                                                 |
|             var   := "value"                                    |
|             hello := "Hello World!"                             |
|             path  := "/foo/bar"                                 |
|             list  := [ "red", "green", "blue" ]                 |
|             keys  := [("semi",";"),("dot","."),("comma",",")]   |
|                                                                 |
| Op       Expression            Expansion                        |
|-----------------------------------------------------------------|
|     | String expansion with value modifiers         (Sec 3.2.2) |
|     |                                                           |
|     |    {var:3}               val                              |
|     |    {var:30}              value                            |
|     |    {list}                red,green,blue                   |
|     |    {list*}               red,green,blue                   |
|     |    {keys}                semi,%3B,dot,.,comma,%2C         |
|     |    {keys*}               semi=%3B,dot=.,comma=%2C         |
|     |                                                           |
|-----+-----------------------------------------------------------|
|  +  | Reserved expansion with value modifiers       (Sec 3.2.3) |
|     |                                                           |
|     |    {+path:6}/here        /foo/b/here                      |
|     |    {+list}               red,green,blue                   |
|     |    {+list*}              red,green,blue                   |
|     |    {+keys}               semi,;,dot,.,comma,,             |
|     |    {+keys*}              semi=;,dot=.,comma=,             |
|     |                                                           |
|-----+-----------------------------------------------------------|
|  #  | Fragment expansion with value modifiers       (Sec 3.2.4) |
|     |                                                           |
|     |    {#path:6}/here        #/foo/b/here                     |
|     |    {#list}               #red,green,blue                  |
|     |    {#list*}              #red,green,blue                  |
|     |    {#keys}               #semi,;,dot,.,comma,,            |
|     |    {#keys*}              #semi=;,dot=.,comma=,            |
|     |                                                           |
|-----+-----------------------------------------------------------|
|  .  | Label expansion, dot-prefixed                 (Sec 3.2.5) |
|     |                                                           |
|     |    X{.var:3}             X.val                            |
|     |    X{.list}              X.red,green,blue                 |
|     |    X{.list*}             X.red.green.blue                 |
|     |    X{.keys}              X.semi,%3B,dot,.,comma,%2C       |
|     |    X{.keys*}             X.semi=%3B.dot=..comma=%2C       |
|     |                                                           |
|-----+-----------------------------------------------------------|
|  /  | Path segments, slash-prefixed                 (Sec 3.2.6) |
|     |                                                           |
|     |    {/var:1,var}          /v/value                         |
|     |    {/list}               /red,green,blue                  |
|     |    {/list*}              /red/green/blue                  |
|     |    {/list*,path:4}       /red/green/blue/%2Ffoo           |
|     |    {/keys}               /semi,%3B,dot,.,comma,%2C        |
|     |    {/keys*}              /semi=%3B/dot=./comma=%2C        |
|     |                                                           |
|-----+-----------------------------------------------------------|
|  ;  | Path-style parameters, semicolon-prefixed     (Sec 3.2.7) |
|     |                                                           |
|     |    {;hello:5}            ;hello=Hello                     |
|     |    {;list}               ;list=red,green,blue             |
|     |    {;list*}              ;red;green;blue                  |
|     |    {;keys}               ;keys=semi,%3B,dot,.,comma,%2C   |
|     |    {;keys*}              ;semi=%3B;dot=.;comma=%2C        |
|     |                                                           |
|-----+-----------------------------------------------------------|
|  ?  | Form-style query, ampersand-separated         (Sec 3.2.8) |
|     |                                                           |
|     |    {?var:3}              ?var=val                         |
|     |    {?list}               ?list=red,green,blue             |
|     |    {?list*}              ?red&amp;green&amp;blue                  |
|     |    {?keys}               ?keys=semi,%3B,dot,.,comma,%2C   |
|     |    {?keys*}              ?semi=%3B&amp;dot=.&amp;comma=%2C        |
|     |                                                           |
|-----+-----------------------------------------------------------|
|  &amp;  | Form-style query continuation                 (Sec 3.2.9) |
|     |                                                           |
|     |    {&amp;var:3}              &amp;var=val                         |
|     |    {&amp;list}               &amp;list=red,green,blue             |
|     |    {&amp;list*}              &amp;red&amp;green&amp;blue                  |
|     |    {&amp;keys}               &amp;keys=semi,%3B,dot,.,comma,%2C   |
|     |    {&amp;keys*}              &amp;semi=%3B&amp;dot=.&amp;comma=%2C        |
|     |                                                           |
`-----------------------------------------------------------------'
</pre></div>
<a name="design"></a><br /><hr />
<table summary="layout" cellpadding="0" cellspacing="2" class="TOCbug" align="right"><tr><td class="TOCbug"><a href="#toc">&nbsp;TOC&nbsp;</a></td></tr></table>
<a name="rfc.section.1.3"></a><h3>1.3.&nbsp;
Design Considerations</h3>

<p>
     Mechanisms similar to URI Templates have been defined within
     several specifications, including WSDL, WADL and OpenSearch.
     This specification extends and formally defines the syntax so
     that URI Templates can be used consistently across multiple
     Internet applications and within Internet message fields,
     while at the same time retaining compatibility with those
     earlier definitions.
    
</p>
<p>
     The URI Template syntax has been designed to carefully balance
     the need for a powerful expansion mechanism with the need for
     ease of implementation. The syntax is designed to be trivial
     to parse while at the same time providing enough flexibility to
     express many common template scenarios.  Implementations are able
     to parse the template and perform the expansions in a single pass.
    
</p>
<p>
     Templates are simple and readable when used with common
     examples because the single-character operators match the URI
     generic syntax delimiters.  The operator's associated delimiter
     (".", ";", "/", "?", "&amp;", and "#") is omitted when none of the
     listed variables are defined.  Likewise, the expansion process for ";"
     (path-style parameters) will omit the "=" when the variable value
     is empty, whereas the process for "?" (form-style parameters)
     will not omit the "=" when the value is empty.  Multiple variables
     and list values have their values joined with "," if there is no
     predefined joining mechanism for the operator.  The "+" and "#"
     operators will substitute unencoded reserved characters found
     inside the variable values; the other operators will pct-encode
     reserved characters found in the variable values prior to expansion.
    
</p>
<p>
     The most common cases for URI spaces can be described with
     Level 1 template expressions.  If we were only concerned with
     URI generation, then the template syntax could be limited to
     just simple variable expansion, since more complex forms could
     be generated by changing the variable values.  However, URI
     Templates have the additional goal of describing the layout of
     identifiers in terms of preexisting data values.  The template
     syntax therefore includes operators that reflect how
     resource identifiers are commonly allocated.  Likewise, since
     prefix substrings are often used to partition large spaces of
     resources, modifiers on variable values provide a way
     to specify both the substring and the full value string
     with a single variable name.
    
</p>
<a name="limitations"></a><br /><hr />
<table summary="layout" cellpadding="0" cellspacing="2" class="TOCbug" align="right"><tr><td class="TOCbug"><a href="#toc">&nbsp;TOC&nbsp;</a></td></tr></table>
<a name="rfc.section.1.4"></a><h3>1.4.&nbsp;
Limitations</h3>

<p>
     Since a URI Template describes a superset of the identifiers,
     there is no implication that every possible expansion for
     each delimited variable expression corresponds to a URI of an
     existing resource.  Our expectation is that an application
     constructing URIs according to the template will be provided
     with an appropriate set of values for the variables being
     substituted, or at least a means of validating user data-entry
     for those values.
    
</p>
<p>
     URI Templates are not URIs: they do not identify
     an abstract or physical resource, they are not parsed as URIs,
     and should not be used in places where a URI would be expected
     unless the template expressions will be expanded by a template
     processor prior to use.  Distinct field, element, or attribute
     names should be used to differentiate protocol elements that
     carry a URI Template from those that expect a URI reference.
    
</p>
<p>
     Some URI Templates can be used in reverse for the purpose of
     variable matching: comparing the template to a fully formed
     URI in order to extract the variable parts from that URI and
     assign them to the named variables.  Variable matching only works
     well if the template expressions are delimited by the beginning or
     end of the URI or by characters that cannot be part of the
     expansion, such as reserved characters surrounding a simple
     string expression.  In general, regular expression languages
     are better suited for variable matching.
    
</p>
<a name="notation"></a><br /><hr />
<table summary="layout" cellpadding="0" cellspacing="2" class="TOCbug" align="right"><tr><td class="TOCbug"><a href="#toc">&nbsp;TOC&nbsp;</a></td></tr></table>
<a name="rfc.section.1.5"></a><h3>1.5.&nbsp;
Notational Conventions</h3>

<p>
     The key words "MUST", "MUST NOT", "REQUIRED", "SHALL",
     "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED",
     "MAY", and "OPTIONAL" in this document are to be
     interpreted as described in <a class='info' href='#RFC2119'>[RFC2119]<span> (</span><span class='info'>Bradner, S., &ldquo;Key words for use in RFCs to Indicate Requirement Levels,&rdquo; March&nbsp;1997.</span><span>)</span></a>.
    
</p>
<p>
     This specification uses the Augmented Backus-Naur Form (ABNF)
     notation of <a class='info' href='#RFC5234'>[RFC5234]<span> (</span><span class='info'>Crocker, D. and P. Overell, &ldquo;Augmented BNF for Syntax Specifications: ABNF,&rdquo; January&nbsp;2008.</span><span>)</span></a>.  The following ABNF rules
     are imported from the normative references <a class='info' href='#RFC5234'>[RFC5234]<span> (</span><span class='info'>Crocker, D. and P. Overell, &ldquo;Augmented BNF for Syntax Specifications: ABNF,&rdquo; January&nbsp;2008.</span><span>)</span></a>,
     <a class='info' href='#RFC3986'>[RFC3986]<span> (</span><span class='info'>Berners-Lee, T., Fielding, R., and L. Masinter, &ldquo;Uniform Resource Identifier (URI): Generic Syntax,&rdquo; January&nbsp;2005.</span><span>)</span></a>, and <a class='info' href='#RFC3987'>[RFC3987]<span> (</span><span class='info'>Duerst, M. and M. Suignard, &ldquo;Internationalized Resource Identifiers (IRIs),&rdquo; January&nbsp;2005.</span><span>)</span></a>.
    
</p><div style='display: table; width: 0; margin-left: 3em; margin-right: auto'><pre>
  <dfn>ALPHA</dfn>          =  <span class='val'>%x41-5A</span> / <span class='val'>%x61-7A</span>   <em>; A-Z / a-z</em>
  <dfn>DIGIT</dfn>          =  <span class='val'>%x30-39</span>             <em>; 0-9</em>
  <dfn>HEXDIG</dfn>         =  <cite class='key'>DIGIT</cite> / "<span class='str'>A</span>" / "<span class='str'>B</span>" / "<span class='str'>C</span>" / "<span class='str'>D</span>" / "<span class='str'>E</span>" / "<span class='str'>F</span>"

  <dfn>pct-encoded</dfn>    =  "<span class='str'>%</span>" <cite class='key'>HEXDIG</cite> <cite class='key'>HEXDIG</cite>
  <dfn>unreserved</dfn>     =  <cite class='key'>ALPHA</cite> / <cite class='key'>DIGIT</cite> / "<span class='str'>-</span>" / "<span class='str'>.</span>" / "<span class='str'>_</span>" / "<span class='str'>~</span>"
  <dfn>reserved</dfn>       =  <cite class='id'>gen-delims</cite> / <cite class='id'>sub-delims</cite>
  <dfn>gen-delims</dfn>     =  "<span class='str'>:</span>" / "<span class='str'>/</span>" / "<span class='str'>?</span>" / "<span class='str'>#</span>" / "<span class='str'>[</span>" / "<span class='str'>]</span>" / "<span class='str'>@</span>"
  <dfn>sub-delims</dfn>     =  "<span class='str'>!</span>" / "<span class='str'>$</span>" / "<span class='str'>&amp;</span>" / "<span class='str'>'</span>" / "<span class='str'>(</span>" / "<span class='str'>)</span>"
                 /  "<span class='str'>*</span>" / "<span class='str'>+</span>" / "<span class='str'>,</span>" / "<span class='str'>;</span>" / "<span class='str'>=</span>"

  <dfn>ucschar</dfn>        =  <span class='val'>%xA0-D7FF</span> / <span class='val'>%xF900-FDCF</span> / <span class='val'>%xFDF0-FFEF</span>
                 /  <span class='val'>%x10000-1FFFD</span> / <span class='val'>%x20000-2FFFD</span> / <span class='val'>%x30000-3FFFD</span>
                 /  <span class='val'>%x40000-4FFFD</span> / <span class='val'>%x50000-5FFFD</span> / <span class='val'>%x60000-6FFFD</span>
                 /  <span class='val'>%x70000-7FFFD</span> / <span class='val'>%x80000-8FFFD</span> / <span class='val'>%x90000-9FFFD</span>
                 /  <span class='val'>%xA0000-AFFFD</span> / <span class='val'>%xB0000-BFFFD</span> / <span class='val'>%xC0000-CFFFD</span>
                 /  <span class='val'>%xD0000-DFFFD</span> / <span class='val'>%xE1000-EFFFD</span>

  <dfn>iprivate</dfn>       =  <span class='val'>%xE000-F8FF</span> / <span class='val'>%xF0000-FFFFD</span> / <span class='val'>%x100000-10FFFD</span>
</pre></div>
<a name="unicode-normal"></a><br /><hr />
<table summary="layout" cellpadding="0" cellspacing="2" class="TOCbug" align="right"><tr><td class="TOCbug"><a href="#toc">&nbsp;TOC&nbsp;</a></td></tr></table>
<a name="rfc.section.1.6"></a><h3>1.6.&nbsp;
Character Encoding and Unicode Normalization</h3>

<p>
     This specification uses the terms "character" and "coded
     character set" in accordance with the definitions provided
     in <a class='info' href='#RFC2978'>[RFC2978]<span> (</span><span class='info'>Freed, N. and J. Postel, &ldquo;IANA Charset Registration Procedures,&rdquo; October&nbsp;2000.</span><span>)</span></a>, and "character encoding" in
     place of what <a class='info' href='#RFC2978'>[RFC2978]<span> (</span><span class='info'>Freed, N. and J. Postel, &ldquo;IANA Charset Registration Procedures,&rdquo; October&nbsp;2000.</span><span>)</span></a> refers to as a "charset".
    
</p>
<p>
     The ABNF notation defines its terminal values to be
     non-negative integers (codepoints) that are a superset of the
     US-ASCII coded character set <a class='info' href='#ASCII'>[ASCII]<span> (</span><span class='info'>American National Standards Institute, &ldquo;Coded Character Set - 7-bit American Standard Code for Information Interchange,&rdquo; 1986.</span><span>)</span></a>.  This
     specification defines terminal values as codepoints within the
     Unicode coded character set <a class='info' href='#UNIV4'>[UNIV4]<span> (</span><span class='info'>The Unicode Consortium, &ldquo;The Unicode Standard, Version                   4.0.1, defined by: The Unicode Standard, Version 4.0                   (Reading, MA, Addison-Wesley, 2003. ISBN                   0-321-18578-1), as amended by Unicode 4.0.1                   (http://www.unicode.org/versions/Unicode4.0.1/),&rdquo; March&nbsp;2004.</span><span>)</span></a>.
    
</p>
<p>
     In spite of the syntax and template expansion process being defined
     in terms of Unicode codepoints, it should be understood that
     templates occur in practice as a sequence of characters in
     whatever form or encoding is suitable for the context in which
     they occur, whether that be octets embedded in a network protocol
     element or paint applied to the side of a bus.
     This specification does not mandate any particular character encoding
     for mapping between URI Template characters and the octets used to
     store or transmit those characters.
     When a URI Template appears in a protocol element, the character
     encoding is defined by that protocol; without such a definition,
     a URI Template is assumed to be in the same character encoding as
     the surrounding text.  It is only during the process of template
     expansion that a string of characters in a URI Template is REQUIRED
     to be processed as a sequence of Unicode codepoints.
    
</p>
<p>
     The Unicode Standard <a class='info' href='#UNIV4'>[UNIV4]<span> (</span><span class='info'>The Unicode Consortium, &ldquo;The Unicode Standard, Version                   4.0.1, defined by: The Unicode Standard, Version 4.0                   (Reading, MA, Addison-Wesley, 2003. ISBN                   0-321-18578-1), as amended by Unicode 4.0.1                   (http://www.unicode.org/versions/Unicode4.0.1/),&rdquo; March&nbsp;2004.</span><span>)</span></a> defines various
     equivalences between sequences of characters for various purposes.
     Unicode Standard Annex #15 <a class='info' href='#UTR15'>[UTR15]<span> (</span><span class='info'>Davis, M. and M. Duerst, &ldquo;Unicode Normalization Forms,&rdquo; April&nbsp;2003.</span><span>)</span></a> defines various
     Normalization Forms for these equivalences.  The normalization form
     determines how to consistently encode equivalent strings.
     In theory, all URI processing implementations, including template
     processors, should use the same normalization form for generating
     a URI reference.  In practice, they do not.  If a value has been
     provided by the same server as the resource, then it can be assumed
     that the string is already in the form expected by that server.
     If a value is provided by a user, such as via a data-entry dialog,
     then the string SHOULD be normalized as Normalization Form C
     (NFC: Canonical Decomposition, followed by Canonical Composition)
     prior to being used in expansions by a template processor.
    
</p>
<p>
     Likewise, when non-ASCII data that represents readable strings is
     pct-encoded for use in a URI reference, a template processor MUST
     first encode the string as UTF-8 <a class='info' href='#RFC3629'>[RFC3629]<span> (</span><span class='info'>Yergeau, F., &ldquo;UTF-8, a transformation format of ISO 10646,&rdquo; November&nbsp;2003.</span><span>)</span></a> and then
     pct-encode any octets that are not allowed in a URI reference.
    
</p>
<a name="syntax"></a><br /><hr />
<table summary="layout" cellpadding="0" cellspacing="2" class="TOCbug" align="right"><tr><td class="TOCbug"><a href="#toc">&nbsp;TOC&nbsp;</a></td></tr></table>
<a name="rfc.section.2"></a><h3>2.&nbsp;
Syntax</h3>

<p>
    A URI Template is a string of printable Unicode characters
    that contains zero or more embedded variable expressions, each
    expression being delimited by a matching pair of braces ('{', '}').
   
</p><div style='display: table; width: 0; margin-left: 3em; margin-right: auto'><pre>
  <dfn>URI-Template</dfn>  = <span class='rep'>*</span>( <cite class='id'>literals</cite> / <cite class='id'>expression</cite> )
</pre></div>
<p>
    Although templates (and template processor implementations) are
    described above in terms of four gradual levels, we define the
    URI-Template syntax in terms of the ABNF for Level 4.  A template
    processor limited to lower level templates MAY exclude the ABNF
    rules applicable only to higher levels.  However, it is RECOMMENDED
    that all parsers implement the full syntax such that unsupported
    levels can be properly identified as such to the end user.
   
</p>
<a name="literals"></a><br /><hr />
<table summary="layout" cellpadding="0" cellspacing="2" class="TOCbug" align="right"><tr><td class="TOCbug"><a href="#toc">&nbsp;TOC&nbsp;</a></td></tr></table>
<a name="rfc.section.2.1"></a><h3>2.1.&nbsp;
Literals</h3>

<p>
     The characters outside of expressions in a URI Template string
     are intended to be copied literally to the URI-reference if the
     character is allowed in a URI (reserved / unreserved / pct-encoded)
     or, if not allowed, copied to the URI-reference in its UTF-8
     pct-encoded form.
    
</p><div style='display: table; width: 0; margin-left: 3em; margin-right: auto'><pre>
  <dfn>literals</dfn>      =  <span class='val'>%x21</span> / <span class='val'>%x23-24</span> / <span class='val'>%x26</span> / <span class='val'>%x28-3B</span> / <span class='val'>%x3D</span> / <span class='val'>%x3F-5B</span>
                /  <span class='val'>%x5D-5F</span> / <span class='val'>%x61-7A</span> / <span class='val'>%x7E</span> / <cite class='id'>ucschar</cite> / <cite class='id'>iprivate</cite>
                /  <cite class='id'>pct-encoded</cite>
                     <em>; any Unicode character except: CTL, SP,</em>
                     <em>;  DQUOTE, "'", "%" (aside from pct-encoded),</em>
                     <em>;  "&lt;", "&gt;", "\", "^", "`", "{", "|", "}"</em>
</pre></div>
<a name="expressions"></a><br /><hr />
<table summary="layout" cellpadding="0" cellspacing="2" class="TOCbug" align="right"><tr><td class="TOCbug"><a href="#toc">&nbsp;TOC&nbsp;</a></td></tr></table>
<a name="rfc.section.2.2"></a><h3>2.2.&nbsp;
Expressions</h3>

<p>
     Template expressions are the parameterized parts of a URI Template.
     Each expression contains an optional operator, which defines the
     expression type and its corresponding expansion process, followed by a
     comma-separated list of variable specifiers (variable names and
     optional value modifiers).  If no operator is provided, the expression
     defaults to simple variable expansion of unreserved values.
    
</p><div style='display: table; width: 0; margin-left: 3em; margin-right: auto'><pre>
  <dfn>expression</dfn>    =  "<span class='str'>{</span>" [ <cite class='id'>operator</cite> ] <cite class='id'>variable-list</cite> "<span class='str'>}</span>"
  <dfn>operator</dfn>      =  "<span class='str'>+</span>" / "<span class='str'>#</span>" / "<span class='str'>.</span>" / "<span class='str'>/</span>" / "<span class='str'>;</span>" / "<span class='str'>?</span>" / "<span class='str'>&amp;</span>"
                /  <cite class='id'>op-reserve</cite>
  <dfn>op-reserve</dfn>    =  "<span class='str'>=</span>" / "<span class='str'>,</span>" / "<span class='str'>!</span>" / "<span class='str'>@</span>" / "<span class='str'>|</span>"
                       <em>; reserved for local use: "$" / "(" / ")"</em>
</pre></div>
<p> 
     The operator characters have been chosen to reflect each of their roles
     as reserved characters in the URI generic syntax.  The operators defined
     in <a class='info' href='#expansion'>Section&nbsp;3<span> (</span><span class='info'>Expansion</span><span>)</span></a> of this specification include:
    
</p><div style='display: table; width: 0; margin-left: 3em; margin-right: auto'><pre>
   +   Reserved character strings;

   #   Fragment identifiers prefixed by "#";

   .   Name labels or extensions prefixed by ".";

   /   Path segments prefixed by "/";

   ;   Path parameter name or name=value pairs prefixed by ";";

   ?   Query component beginning with "?" and consisting of
       name=value pairs separated by "&amp;"; and,

   &amp;   Continuation of query-style &amp;name=value pairs within
       a literal query component.
</pre></div>
<p>
     The operator characters equals ("="), comma (","), exclamation ("!"),
     at-sign ("@"), and pipe ("|") are reserved for future extensions.
    
</p>
<p>
     The expression syntax specifically excludes use of the dollar ("$")
     and parentheses ["(" and ")"] characters so that they remain
     available for local language extensions outside the scope of this
     specification.
    
</p>
<a name="variables"></a><br /><hr />
<table summary="layout" cellpadding="0" cellspacing="2" class="TOCbug" align="right"><tr><td class="TOCbug"><a href="#toc">&nbsp;TOC&nbsp;</a></td></tr></table>
<a name="rfc.section.2.3"></a><h3>2.3.&nbsp;
Variables</h3>

<p>
     After the operator (if any), each expression contains a list of
     one or more comma-separated variable specifiers (varspec).
     The variable names serve multiple purposes: documentation for
     what kinds of values are expected, identifiers for associating
     values within a template processor, and the literal string to use
     for the name in name=value expansions (aside from when exploding
     an associative array).
    
</p><div style='display: table; width: 0; margin-left: 3em; margin-right: auto'><pre>
  <dfn>variable-list</dfn> =  <cite class='id'>varspec</cite> <span class='rep'>*</span>( "<span class='str'>,</span>" <cite class='id'>varspec</cite> )
  <dfn>varspec</dfn>       =  <cite class='id'>varname</cite> [ <cite class='id'>modifier</cite> ]
  <dfn>varname</dfn>       =  <cite class='id'>varchar</cite> <span class='rep'>*</span>( <cite class='id'>varchar</cite> / "<span class='str'>.</span>" )
  <dfn>varchar</dfn>       =  <cite class='key'>ALPHA</cite> / <cite class='key'>DIGIT</cite> / "<span class='str'>_</span>" / <cite class='id'>pct-encoded</cite>
</pre></div>
<p>
     A varname MAY contain one or more pct-encoded triplets.
     These triplets are considered an essential part of the variable name
     and are not decoded during processing.
     A varname containing pct-encoded characters is not the same variable
     as a varname with those same characters decoded.  Applications that
     provide URI Templates are expected to be consistent in their use of
     pct-encoding within variable names.
    
</p>
<p>
     An expression MAY reference variables that are unknown
     to the template processor or whose value is set to a special
     "undefined" value, such as undef or null.  Such undefined
     variables are given special treatment by the expansion process.
    
</p>
<p>
     A variable value that is a string of length zero is not considered
     undefined; it has the defined value of an empty string.
    
</p>
<p>
     A variable may have a composite value in the form of a
     list of values or an associative array of (name, value) pairs.
     Such value types are not directly indicated by the template
     syntax, but do have an impact on the expansion process.  A
     composite value with zero member values is considered undefined.
    
</p>
<a name="modifiers"></a><br /><hr />
<table summary="layout" cellpadding="0" cellspacing="2" class="TOCbug" align="right"><tr><td class="TOCbug"><a href="#toc">&nbsp;TOC&nbsp;</a></td></tr></table>
<a name="rfc.section.2.4"></a><h3>2.4.&nbsp;
Value Modifiers</h3>

<p>
     Each of the variables in a Level 4 template expression can have
     a modifier indicating either that its expansion is limited to a
     prefix of the variable's value string or that its expansion is
     exploded as a composite value in the form of a value list or
     an associative array of (name, value) pairs.
    
</p><div style='display: table; width: 0; margin-left: 3em; margin-right: auto'><pre>
  <dfn>modifier</dfn>      =  <cite class='id'>prefix</cite> / <cite class='id'>explode</cite>
</pre></div>
<a name="prefix-values"></a><br /><hr />
<table summary="layout" cellpadding="0" cellspacing="2" class="TOCbug" align="right"><tr><td class="TOCbug"><a href="#toc">&nbsp;TOC&nbsp;</a></td></tr></table>
<a name="rfc.section.2.4.1"></a><h3>2.4.1.&nbsp;
Prefix Values</h3>

<p>
      A prefix modifier indicates that the variable expansion is limited
      to a prefix of the variable's value string.  Prefix modifiers are
      often used to partition an identifier space hierarchically, as is
      common in reference indices and hash-based storage.  It also serves
      to limit the expanded value to a maximum number of characters.
      Prefix modifiers are not applicable to variables that have composite
      values.
     
</p><div style='display: table; width: 0; margin-left: 3em; margin-right: auto'><pre>
  <dfn>prefix</dfn>        =  "<span class='str'>:</span>" <cite class='id'>max-length</cite>
  <dfn>max-length</dfn>    =  <span class='val'>%x31-39</span> <span class='rep'>*</span><cite class='key'>DIGIT</cite>   <em>; positive integer</em>
</pre></div>
<p>
      The max-length is a positive integer that refers to a maximum number
      of characters from the beginning of the variable's value as a
      Unicode string.
      Note that this numbering is in characters, not octets, in order to
      avoid splitting between the octets of a multi-octet UTF-8 encoded
      character or within a pct-encoded triplet.
      If the max-length is greater than the length of the variable's
      value, then the entire value string is used.
     
</p>
<p>For example,
</p><div style='display: table; width: 0; margin-left: 3em; margin-right: auto'><pre>
  Given the variable assignments

    var   := "value"
    semi  := ";"

  Example Template     Expansion

    {var}              value
    {var:20}           value
    {var:3}            val
    {semi}             %3B
    {semi:2}           %3B
</pre></div>
<a name="composite-values"></a><br /><hr />
<table summary="layout" cellpadding="0" cellspacing="2" class="TOCbug" align="right"><tr><td class="TOCbug"><a href="#toc">&nbsp;TOC&nbsp;</a></td></tr></table>
<a name="rfc.section.2.4.2"></a><h3>2.4.2.&nbsp;
Composite Values</h3>

<p>
      An explode ("*") modifier indicates that the variable is to be treated
      as a composite value consisting of either a list of names or an
      associative array of (name, value) pairs.  Hence, the expansion
      process is applied to each member of the composite as if it were
      listed as a separate variable.  This kind of variable specification
      is significantly less self-documenting than non-exploded variables,
      since there is less correspondence between the variable name and
      how the URI reference appears after expansion.
     
</p><div style='display: table; width: 0; margin-left: 3em; margin-right: auto'><pre>
  <dfn>explode</dfn>       =  "<span class='str'>*</span>"
</pre></div>
<p>
      Since URI Templates do not contain an indication of type or schema,
      the type for an exploded variable is assumed to be determined by
      context.  For example, the processor might be supplied values in a
      form that differentiates values as strings, lists, or associative
      arrays.  Likewise, the context in which the template is used
      (script, mark-up language, IDL, etc.) might define rules for
      associating variable names with types, structures, or schema.
     
</p>
<p>
      Explode modifiers improve brevity in the URI Template syntax.
      For example, a resource that provides a geographic map for a
      given street address might accept a hundred permutations on
      fields for address input, including partial addresses (e.g.,
      just the city or postal code).  Such a resource could be
      described as a template with each and every address component
      listed in order, or with a far more simple template that makes
      use of an explode modifier, as in
     
</p><div style='display: table; width: 0; margin-left: 3em; margin-right: auto'><pre>
   /mapper{?address*}
</pre></div>
<p>
      along with some context that defines what the variable named
      "address" can include, such as by reference to some other
      standard for addressing (e.g., UPU S42 or AS/NZS 4819:2003).
      A recipient aware of the schema can then provide appropriate
      expansions, such as:
     
</p><div style='display: table; width: 0; margin-left: 3em; margin-right: auto'><pre>
   /mapper?city=Newport%20Beach&amp;state=CA
</pre></div>
<p>
      The expansion process for exploded variables is dependent on
      both the operator being used and whether the composite value is to
      be treated as a list of values or as an associative array of
      (name, value) pairs.  Structures are processed as if they are an
      associative array with names corresponding to the fields in the
      structure definition and "." separators used to indicate name
      hierarchy in substructures.
     
</p>
<a name="expansion"></a><br /><hr />
<table summary="layout" cellpadding="0" cellspacing="2" class="TOCbug" align="right"><tr><td class="TOCbug"><a href="#toc">&nbsp;TOC&nbsp;</a></td></tr></table>
<a name="rfc.section.3"></a><h3>3.&nbsp;
Expansion</h3>

<p>
    The process of URI Template expansion is to scan the template
    string from beginning to end, copying literal characters
    and replacing each expression with the result of applying the
    expression's operator to the value of each variable named in
    the expression.  Each variable's value MUST be formed prior to
    template expansion.
   
</p>
<p>
    The requirements on expansion for each aspect of the URI Template
    grammar are defined in this section.  A non-normative algorithm for
    the expansion process as a whole is provided in
    <a class='info' href='#implementation'>Appendix&nbsp;A<span> (</span><span class='info'>Implementation Hints</span><span>)</span></a>.
   
</p>
<p>
    If a template processor encounters an error outside of an expression,
    such as a character sequence that does not match the &lt;URI-Template&gt;
    grammar, then processing of the template SHOULD cease, the URI-reference
    result SHOULD contain the expanded part of the template followed by the
    remainder unexpanded, and the location and type of error SHOULD be
    indicated to the invoking application.  If an error is encountered inside
    an expression, such as an operator or value modifier that it does not
    recognize or cannot support, then the expression SHOULD be copied to
    the result unexpanded, processing of the remainder of the template
    SHOULD continue, and the location and type of error SHOULD be indicated
    to the invoking application.  If an error occurs, the result returned
    might not be a valid URI reference; it will be an incompletely expanded
    template string that is only intended for diagnostic use.
   
</p>
<a name="literal-expansion"></a><br /><hr />
<table summary="layout" cellpadding="0" cellspacing="2" class="TOCbug" align="right"><tr><td class="TOCbug"><a href="#toc">&nbsp;TOC&nbsp;</a></td></tr></table>
<a name="rfc.section.3.1"></a><h3>3.1.&nbsp;
Literal Expansion</h3>

<p>
     If the literal character is allowed anywhere in the URI
     syntax (unreserved / reserved / pct-encoded ), then it is copied
     directly to the result string.  Otherwise, the pct-encoded equivalent
     of the literal character is copied to the result string by
     encoding the character in UTF-8 (a sequence of octets) and
     then encoding each octet as a pct-encoded triplet.
    
</p>
<a name="expression-expansion"></a><br /><hr />
<table summary="layout" cellpadding="0" cellspacing="2" class="TOCbug" align="right"><tr><td class="TOCbug"><a href="#toc">&nbsp;TOC&nbsp;</a></td></tr></table>
<a name="rfc.section.3.2"></a><h3>3.2.&nbsp;
Expression Expansion</h3>

<p>
     Each expression is indicated by an opening brace ("{") character
     and continues until the next closing brace ("}").  The expression
     is expanded by determining the expression type and then following
     that type's expansion process for each comma-separated varspec
     in the expression.  Level 1 templates are limited to the default
     operator (simple string value expansion) and a single variable
     per expression.  Level 2 templates are limited to a single
     varspec per expression.
    
</p>
<p>
     The expression type is determined by looking at the first
     character after the opening brace.  If the character is an
     operator, then remember the expression type associated with
     that operator for later expansion decisions and skip to the
     next character for the variable-list.  If the first character
     is not an operator, then the expression type is simple string
     expansion and the first character is the beginning of the
     variable-list.
    
</p>
<p>The examples in the subsections below use
    the following definitions for variable values:
</p><div style='display: table; width: 0; margin-left: 3em; margin-right: auto'><pre>

      dom   := "example.com"
      dub   := "me/too"
      hello := "Hello World!"
      half  := "50%"
      var   := "value"
      who   := "fred"
      base  := "http://example.com/home/"
      path  := "/foo/bar"
      list  := [ "red", "green", "blue" ]
      keys  := [("semi",";"),("dot","."),("comma",",")]
      v     := "6"
      x     := "1024"
      y     := "768"
      empty := ""
      empty_keys  := []
      undef := null
</pre></div>
<a name="variable-expansion"></a><br /><hr />
<table summary="layout" cellpadding="0" cellspacing="2" class="TOCbug" align="right"><tr><td class="TOCbug"><a href="#toc">&nbsp;TOC&nbsp;</a></td></tr></table>
<a name="rfc.section.3.2.1"></a><h3>3.2.1.&nbsp;
Variable Expansion</h3>

<p>
      A variable that is undefined has no value and is ignored by the
      expansion process.  A variable defined as a list value is considered
      undefined if the list contains zero members.  A variable defined as
      an associative array of (name, value) pairs is considered undefined
      if the array contains zero members or if all member names in the array
      have undefined values.
      If all of the variables in an expression are undefined, then the
      expression's expansion is the empty string.
     
</p>
<p>
      Variable expansion of a defined, non-empty value results in a
      substring of allowed URI characters.  A template processor MUST
      encode the value string as UTF-8 and transform each octet that
      is not in the allowed set into the corresponding pct-encoded triplet.
      The allowed set depends on the expression type: reserved ("+")
      and fragment ("#") expansions allow the set of characters in
      ( unreserved / reserved / pct-encoded ) to be passed through without
      pct-encoding, whereas all other expression types allow only unreserved
      characters to be passed through without pct-encoding.  Note that
      the percent character ("%") is only allowed as part of a pct-encoded
      triplet and only for reserved/fragment expansion: in all other cases,
      a value of "%" MUST be pct-encoded as "%25" by variable expansion.
     
</p>
<p>
      If a variable appears more than once in an expression or
      within multiple expressions of a URI Template, the value of
      that variable MUST remain static throughout the expansion
      process (i.e., the variable must have the same value for the
      purpose of calculating each expansion).  However, if reserved
      characters or pct-encoded triplets occur in the value, they will be
      pct-encoded by some expression types and not by others.
     
</p>
<p>
      For a variable that is a simple string value, expansion consists
      of appending the encoded value to the result string.  The explode
      modifier has no effect.  The prefix modifier limits the expansion to
      the first max-length characters of the decoded value.   If the value
      contains multibyte UTF-8, care must be taken to avoid splitting the
      value in mid-character: count each Unicode codepoint as one character.
     
</p>
<p>
      For a variable that is a list of values, expansion consists of
      concatenating the defined member string values, encoded as above,
      with a separator string inserted between those values.
      If no explode modifier is given, the separator string is a comma (",").
      If an explode modifier is given, the separator string is defined per
      operator by the following table, where NUL is the default expression
      type:
   
</p><div style='display: table; width: 0; margin-left: 3em; margin-right: auto'><pre>
.-----------------------------------------------------------------.
|  operator:  NUL     +      .      /      ;      ?      &amp;     #  |
| separator:  ","    ","    "."    "/"    ";"    "&amp;"    "&amp;"   "," |
`-----------------------------------------------------------------'
</pre></div>
<p>
      For a variable that is an associative array, expansion consists of a
      list of either "name,value" (without explode modifier) or "name=value"
      (with explode modifier) pairs, excluding any pairs for which the
      corresponding value is undefined, with a separator string inserted
      between defined pairs.  The separator string is defined in the same
      way as for list variables above.  Both the name and value strings are
      encoded in the same way as simple string values.
     
</p>
<a name="op-simple"></a><br /><hr />
<table summary="layout" cellpadding="0" cellspacing="2" class="TOCbug" align="right"><tr><td class="TOCbug"><a href="#toc">&nbsp;TOC&nbsp;</a></td></tr></table>
<a name="rfc.section.3.2.2"></a><h3>3.2.2.&nbsp;
Simple String Expansion: {var}</h3>

<p>
      Simple string expansion is the default expression type when no
      operator is given.
     
</p>
<p>
      For each defined variable in the variable-list,
      perform variable expansion, as defined in
      <a class='info' href='#variable-expansion'>Section&nbsp;3.2.1<span> (</span><span class='info'>Variable Expansion</span><span>)</span></a>, with the allowed characters
      being those in the unreserved set.  If more than one variable has
      a defined value, append a comma (",") to the result string as a
      separator between variable expansions.
     
</p><div style='display: table; width: 0; margin-left: 3em; margin-right: auto'><pre>
  Example Template     Expansion

    {var}              value
    {hello}            Hello%20World%21
    {half}             50%25
    O{empty}X          OX
    O{undef}X          OX
    {x,y}              1024,768
    {x,hello,y}        1024,Hello%20World%21,768
    ?{x,empty}         ?1024,
    ?{x,undef}         ?1024
    ?{undef,y}         ?768
    {var:3}            val
    {var:30}           value
    {list}             red,green,blue
    {list*}            red,green,blue
    {keys}             semi,%3B,dot,.,comma,%2C
    {keys*}            semi=%3B,dot=.,comma=%2C
</pre></div>
<a name="op-plus"></a><br /><hr />
<table summary="layout" cellpadding="0" cellspacing="2" class="TOCbug" align="right"><tr><td class="TOCbug"><a href="#toc">&nbsp;TOC&nbsp;</a></td></tr></table>
<a name="rfc.section.3.2.3"></a><h3>3.2.3.&nbsp;
Reserved expansion: {+var}</h3>

<p>
      Reserved expansion, as indicated by the plus ("+") operator for Level 2
      and above templates, is identical to simple string expansion except
      that the substituted values may also contain pct-encoded triplets and
      characters in the reserved set.
     
</p>
<p>
      For each defined variable in the variable-list, perform variable
      expansion, as defined in <a class='info' href='#variable-expansion'>Section&nbsp;3.2.1<span> (</span><span class='info'>Variable Expansion</span><span>)</span></a>, with the
      allowed characters being those in the set
      (unreserved / reserved / pct-encoded).
      If more than one variable has a defined value, append a comma (",")
      to the result string as a separator between variable expansions.
     
</p><div style='display: table; width: 0; margin-left: 3em; margin-right: auto'><pre>
  Example Template        Expansion

    {+var}                value
    {+hello}              Hello%20World!
    {+half}               50%25

    {base}index           http%3A%2F%2Fexample.com%2Fhome%2Findex
    {+base}index          http://example.com/home/index
    O{+empty}X            OX
    O{+undef}X            OX

    {+path}/here          /foo/bar/here
    here?ref={+path}      here?ref=/foo/bar
    up{+path}{var}/here   up/foo/barvalue/here
    {+x,hello,y}          1024,Hello%20World!,768
    {+path,x}/here        /foo/bar,1024/here

    {+path:6}/here        /foo/b/here
    {+list}               red,green,blue
    {+list*}              red,green,blue
    {+keys}               semi,;,dot,.,comma,,
    {+keys*}              semi=;,dot=.,comma=,
</pre></div>
<a name="op-crosshatch"></a><br /><hr />
<table summary="layout" cellpadding="0" cellspacing="2" class="TOCbug" align="right"><tr><td class="TOCbug"><a href="#toc">&nbsp;TOC&nbsp;</a></td></tr></table>
<a name="rfc.section.3.2.4"></a><h3>3.2.4.&nbsp;
Fragment expansion: {#var}</h3>

<p>
      Fragment expansion, as indicated by the crosshatch ("#") operator for
      Level 2 and above templates, is identical to reserved expansion except
      that a crosshatch character (fragment delimiter) is appended first to
      the result string if any of the variables are defined.
     
</p><div style='display: table; width: 0; margin-left: 3em; margin-right: auto'><pre>
  Example Template     Expansion

    {#var}             #value
    {#hello}           #Hello%20World!
    {#half}            #50%25
    foo{#empty}        foo#
    foo{#undef}        foo
    {#x,hello,y}       #1024,Hello%20World!,768
    {#path,x}/here     #/foo/bar,1024/here
    {#path:6}/here     #/foo/b/here
    {#list}            #red,green,blue
    {#list*}           #red,green,blue
    {#keys}            #semi,;,dot,.,comma,,
    {#keys*}           #semi=;,dot=.,comma=,
</pre></div>
<a name="op-dot"></a><br /><hr />
<table summary="layout" cellpadding="0" cellspacing="2" class="TOCbug" align="right"><tr><td class="TOCbug"><a href="#toc">&nbsp;TOC&nbsp;</a></td></tr></table>
<a name="rfc.section.3.2.5"></a><h3>3.2.5.&nbsp;
Label expansion with dot-prefix: {.var}</h3>

<p>
      Label expansion, as indicated by the dot (".") operator for Level 3 
      and above templates, is useful for describing URI spaces with
      varying domain names or path selectors (e.g., filename extensions).
     
</p>
<p>
      For each defined variable in the variable-list, append "." to the
      result string and then perform variable expansion, as defined in
      <a class='info' href='#variable-expansion'>Section&nbsp;3.2.1<span> (</span><span class='info'>Variable Expansion</span><span>)</span></a>, with the allowed characters
      being those in the unreserved set.
     
</p>
<p>
      Since "." is in the unreserved set, a value that contains
      a "." has the effect of adding multiple labels.
     
</p><div style='display: table; width: 0; margin-left: 3em; margin-right: auto'><pre>
  Example Template     Expansion

    {.who}             .fred
    {.who,who}         .fred.fred
    {.half,who}        .50%25.fred
    www{.dom}          www.example.com
    X{.var}            X.value
    X{.empty}          X.
    X{.undef}          X
    X{.var:3}          X.val
    X{.list}           X.red,green,blue
    X{.list*}          X.red.green.blue
    X{.keys}           X.semi,%3B,dot,.,comma,%2C
    X{.keys*}          X.semi=%3B.dot=..comma=%2C
    X{.empty_keys}     X
    X{.empty_keys*}    X
</pre></div>
<a name="op-slash"></a><br /><hr />
<table summary="layout" cellpadding="0" cellspacing="2" class="TOCbug" align="right"><tr><td class="TOCbug"><a href="#toc">&nbsp;TOC&nbsp;</a></td></tr></table>
<a name="rfc.section.3.2.6"></a><h3>3.2.6.&nbsp;
Path segment expansion: {/var}</h3>

<p>
      Path segment expansion, as indicated by the slash ("/") operator
      in Level 3 and above templates, is useful for describing URI
      path hierarchies.
     
</p>
<p>
      For each defined variable in the variable-list, append "/" to the
      result string and then perform variable expansion, as defined in
      <a class='info' href='#variable-expansion'>Section&nbsp;3.2.1<span> (</span><span class='info'>Variable Expansion</span><span>)</span></a>, with the allowed characters
      being those in the unreserved set.
     
</p>
<p>
      Note that the expansion process for path segment expansion is
      identical to that of label expansion aside from the substitution
      of "/" instead of ".".  However, unlike ".", a "/" is a reserved
      character and will be pct-encoded if found in a value.
     
</p><div style='display: table; width: 0; margin-left: 3em; margin-right: auto'><pre>
  Example Template     Expansion

    {/who}             /fred
    {/who,who}         /fred/fred
    {/half,who}        /50%25/fred
    {/who,dub}         /fred/me%2Ftoo
    {/var}             /value
    {/var,empty}       /value/
    {/var,undef}       /value
    {/var,x}/here      /value/1024/here
    {/var:1,var}       /v/value
    {/list}            /red,green,blue
    {/list*}           /red/green/blue
    {/list*,path:4}    /red/green/blue/%2Ffoo
    {/keys}            /semi,%3B,dot,.,comma,%2C
    {/keys*}           /semi=%3B/dot=./comma=%2C
</pre></div>
<a name="op-semicolon"></a><br /><hr />
<table summary="layout" cellpadding="0" cellspacing="2" class="TOCbug" align="right"><tr><td class="TOCbug"><a href="#toc">&nbsp;TOC&nbsp;</a></td></tr></table>
<a name="rfc.section.3.2.7"></a><h3>3.2.7.&nbsp;
Path-style parameter expansion: {;var}</h3>

<p>
      Path-style parameter expansion, as indicated by the semicolon (";")
      operator in Level 3 and above templates, is useful for describing URI
      path parameters, such as "path;property" or "path;name=value".
     
</p>
<p>
      For each defined variable in the variable-list:
      </p>
<ul class="text">
<li>append ";" to the result string;
</li>
<li>if the variable has a simple string value or
          no explode modifier is given, then:
          
<ul class="text">
<li>append the variable name (encoded as if it were a literal
              string) to the result string;
</li>
<li>if the variable's value is not empty, append "=" to the
              result string;
</li>
</ul>
       
</li>
<li>perform variable expansion, as defined in
          <a class='info' href='#variable-expansion'>Section&nbsp;3.2.1<span> (</span><span class='info'>Variable Expansion</span><span>)</span></a>, with the allowed characters
          being those in the unreserved set.
</li>
</ul><p>
     
</p><div style='display: table; width: 0; margin-left: 3em; margin-right: auto'><pre>
  Example Template     Expansion

    {;who}             ;who=fred
    {;half}            ;half=50%25
    {;empty}           ;empty
    {;v,empty,who}     ;v=6;empty;who=fred
    {;v,bar,who}       ;v=6;who=fred
    {;x,y}             ;x=1024;y=768
    {;x,y,empty}       ;x=1024;y=768;empty
    {;x,y,undef}       ;x=1024;y=768
    {;hello:5}         ;hello=Hello
    {;list}            ;list=red,green,blue
    {;list*}           ;red;green;blue
    {;keys}            ;keys=semi,%3B,dot,.,comma,%2C
    {;keys*}           ;semi=%3B;dot=.;comma=%2C
</pre></div>
<a name="op-question"></a><br /><hr />
<table summary="layout" cellpadding="0" cellspacing="2" class="TOCbug" align="right"><tr><td class="TOCbug"><a href="#toc">&nbsp;TOC&nbsp;</a></td></tr></table>
<a name="rfc.section.3.2.8"></a><h3>3.2.8.&nbsp;
Form-style query expansion: {?var}</h3>

<p>
      Form-style query expansion, as indicated by the question-mark ("?")
      operator in Level 3 and above templates, is useful for describing an
      entire optional query component.
     
</p>
<p>
      For each defined variable in the variable-list:
      </p>
<ul class="text">
<li>append "?" to the result string if this is the first defined value
          or append "&amp;" thereafter;
</li>
<li>if the variable has a simple string value or
          no explode modifier is given, append the variable name
          (encoded as if it were a literal string) and an equals
          character ("=") to the result string; and,
</li>
<li>perform variable expansion, as defined in
          <a class='info' href='#variable-expansion'>Section&nbsp;3.2.1<span> (</span><span class='info'>Variable Expansion</span><span>)</span></a>, with the allowed characters
          being those in the unreserved set.
</li>
</ul><p>
     
</p><div style='display: table; width: 0; margin-left: 3em; margin-right: auto'><pre>
  Example Template     Expansion

    {?who}             ?who=fred
    {?half}            ?half=50%25
    {?x,y}             ?x=1024&amp;y=768
    {?x,y,empty}       ?x=1024&amp;y=768&amp;empty=
    {?x,y,undef}       ?x=1024&amp;y=768
    {?var:3}           ?var=val
    {?list}            ?list=red,green,blue
    {?list*}           ?red&amp;green&amp;blue
    {?keys}            ?keys=semi,%3B,dot,.,comma,%2C
    {?keys*}           ?semi=%3B&amp;dot=.&amp;comma=%2C
</pre></div>
<a name="op-ampersand"></a><br /><hr />
<table summary="layout" cellpadding="0" cellspacing="2" class="TOCbug" align="right"><tr><td class="TOCbug"><a href="#toc">&nbsp;TOC&nbsp;</a></td></tr></table>
<a name="rfc.section.3.2.9"></a><h3>3.2.9.&nbsp;
Form-style query continuation: {&amp;var}</h3>

<p>
      Form-style query continuation, as indicated by the ampersand ("&amp;")
      operator in Level 3 and above templates, is useful for describing
      optional &amp;name=value pairs in a template that already contains a
      literal query component with fixed parameters.
     
</p>
<p>
      For each defined variable in the variable-list:
      </p>
<ul class="text">
<li>append "&amp;" to the result string;
</li>
<li>if the variable has a simple string value or no explode modifier
          is given, append the variable name (encoded as if it were a literal
          string) and an equals character ("=") to the result string; and,
</li>
<li>perform variable expansion, as defined in
          <a class='info' href='#variable-expansion'>Section&nbsp;3.2.1<span> (</span><span class='info'>Variable Expansion</span><span>)</span></a>, with the allowed characters
          being those in the unreserved set.
</li>
</ul><p>
     
</p><div style='display: table; width: 0; margin-left: 3em; margin-right: auto'><pre>
  Example Template     Expansion

    {&amp;who}             &amp;who=fred
    {&amp;half}            &amp;half=50%25
    ?fixed=yes{&amp;x}     ?fixed=yes&amp;x=1024
    {&amp;x,y,empty}       &amp;x=1024&amp;y=768&amp;empty=
    {&amp;x,y,undef}       &amp;x=1024&amp;y=768

    {&amp;var:3}           &amp;var=val
    {&amp;list}            &amp;list=red,green,blue
    {&amp;list*}           &amp;red&amp;green&amp;blue
    {&amp;keys}            &amp;keys=semi,%3B,dot,.,comma,%2C
    {&amp;keys*}           &amp;semi=%3B&amp;dot=.&amp;comma=%2C
</pre></div>
<a name="anchor1"></a><br /><hr />
<table summary="layout" cellpadding="0" cellspacing="2" class="TOCbug" align="right"><tr><td class="TOCbug"><a href="#toc">&nbsp;TOC&nbsp;</a></td></tr></table>
<a name="rfc.section.4"></a><h3>4.&nbsp;
Security Considerations</h3>

<p>
    A URI Template does not contain active or executable content. Other
    security considerations are the same as those for URIs, as described
    in section 7 of <a class='info' href='#RFC3986'>[RFC3986]<span> (</span><span class='info'>Berners-Lee, T., Fielding, R., and L. Masinter, &ldquo;Uniform Resource Identifier (URI): Generic Syntax,&rdquo; January&nbsp;2005.</span><span>)</span></a>.
   
</p>
<a name="iana"></a><br /><hr />
<table summary="layout" cellpadding="0" cellspacing="2" class="TOCbug" align="right"><tr><td class="TOCbug"><a href="#toc">&nbsp;TOC&nbsp;</a></td></tr></table>
<a name="rfc.section.5"></a><h3>5.&nbsp;
IANA Considerations</h3>

<p>
    No IANA actions are required by this document.
   
</p>
<a name="ack"></a><br /><hr />
<table summary="layout" cellpadding="0" cellspacing="2" class="TOCbug" align="right"><tr><td class="TOCbug"><a href="#toc">&nbsp;TOC&nbsp;</a></td></tr></table>
<a name="rfc.section.6"></a><h3>6.&nbsp;
Acknowledgments</h3>

<p>
    The following people made significant contributions to this
    specification: Mike Burrows, Michaeljohn Clement, DeWitt Clinton,
    John Cowan, Robbie Gates, James H. Manger, Marc Portier, and James Snell.
   
</p>
<a name="rfc.references1"></a><br /><hr />
<table summary="layout" cellpadding="0" cellspacing="2" class="TOCbug" align="right"><tr><td class="TOCbug"><a href="#toc">&nbsp;TOC&nbsp;</a></td></tr></table>
<h3>7.&nbsp;Normative References</h3>
<table width="99%" border="0">
<tr><td class="author-text" valign="top"><a name="ASCII">[ASCII]</a></td>
<td class="author-text">American National Standards Institute, &ldquo;Coded Character Set - 7-bit American Standard Code for Information Interchange,&rdquo; ANSI&nbsp;X3.4, 1986.</td></tr>
<tr><td class="author-text" valign="top"><a name="RFC2119">[RFC2119]</a></td>
<td class="author-text"><a href="mailto:sob@harvard.edu">Bradner, S.</a>, &ldquo;<a href="http://tools.ietf.org/html/rfc2119">Key words for use in RFCs to Indicate Requirement Levels</a>,&rdquo; BCP&nbsp;14, RFC&nbsp;2119, March&nbsp;1997 (<a href="ftp://ftp.isi.edu/in-notes/rfc2119.txt">TXT</a>, <a href="http://xml.resource.org/public/rfc/html/rfc2119.html">HTML</a>, <a href="http://xml.resource.org/public/rfc/xml/rfc2119.xml">XML</a>).</td></tr>
<tr><td class="author-text" valign="top"><a name="RFC2978">[RFC2978]</a></td>
<td class="author-text">Freed, N. and J. Postel, &ldquo;<a href="http://tools.ietf.org/html/rfc2978">IANA Charset Registration Procedures</a>,&rdquo; BCP&nbsp;19, RFC&nbsp;2978, October&nbsp;2000 (<a href="ftp://ftp.isi.edu/in-notes/rfc2978.txt">TXT</a>).</td></tr>
<tr><td class="author-text" valign="top"><a name="RFC3629">[RFC3629]</a></td>
<td class="author-text">Yergeau, F., &ldquo;<a href="http://tools.ietf.org/html/rfc3629">UTF-8, a transformation format of ISO 10646</a>,&rdquo; STD&nbsp;63, RFC&nbsp;3629, November&nbsp;2003 (<a href="ftp://ftp.isi.edu/in-notes/rfc3629.txt">TXT</a>).</td></tr>
<tr><td class="author-text" valign="top"><a name="RFC3986">[RFC3986]</a></td>
<td class="author-text">Berners-Lee, T., Fielding, R., and L. Masinter, &ldquo;<a href="http://tools.ietf.org/html/rfc3986">Uniform Resource Identifier (URI): Generic Syntax</a>,&rdquo; STD&nbsp;66, RFC&nbsp;3986, January&nbsp;2005 (<a href="ftp://ftp.isi.edu/in-notes/rfc3986.txt">TXT</a>).</td></tr>
<tr><td class="author-text" valign="top"><a name="RFC3987">[RFC3987]</a></td>
<td class="author-text">Duerst, M. and M. Suignard, &ldquo;<a href="http://tools.ietf.org/html/rfc3987">Internationalized Resource Identifiers (IRIs)</a>,&rdquo; RFC&nbsp;3987, January&nbsp;2005 (<a href="ftp://ftp.isi.edu/in-notes/rfc3987.txt">TXT</a>).</td></tr>
<tr><td class="author-text" valign="top"><a name="RFC5234">[RFC5234]</a></td>
<td class="author-text">Crocker, D. and P. Overell, &ldquo;<a href="http://tools.ietf.org/html/rfc5234">Augmented BNF for Syntax Specifications: ABNF</a>,&rdquo; STD&nbsp;68, RFC&nbsp;5234, January&nbsp;2008 (<a href="ftp://ftp.isi.edu/in-notes/rfc5234.txt">TXT</a>).</td></tr>
<tr><td class="author-text" valign="top"><a name="UNIV4">[UNIV4]</a></td>
<td class="author-text">The Unicode Consortium, &ldquo;The Unicode Standard, Version
                  4.0.1, defined by: The Unicode Standard, Version 4.0
                  (Reading, MA, Addison-Wesley, 2003. ISBN
                  0-321-18578-1), as amended by Unicode 4.0.1
                  (http://www.unicode.org/versions/Unicode4.0.1/),&rdquo; March&nbsp;2004.</td></tr>
<tr><td class="author-text" valign="top"><a name="UTR15">[UTR15]</a></td>
<td class="author-text">Davis, M. and M. Duerst, &ldquo;<a href="http://www.unicode.org/unicode/reports/tr15/tr15-23.html">Unicode Normalization Forms</a>,&rdquo; Unicode Standard Annex #&nbsp;15, April&nbsp;2003.</td></tr>
</table>

<a name="implementation"></a><br /><hr />
<table summary="layout" cellpadding="0" cellspacing="2" class="TOCbug" align="right"><tr><td class="TOCbug"><a href="#toc">&nbsp;TOC&nbsp;</a></td></tr></table>
<a name="rfc.section.A"></a><h3>Appendix A.&nbsp;
Implementation Hints</h3>

<p>
    The normative sections on expansion describe each operator with
    a separate expansion process for the sake of descriptive clarity.
    In actual implementations, we expect the expressions to be processed
    left-to-right using a common algorithm that has only minor variations
    in process per operator.  This appendix describes one such algorithm.
   
</p>
<p>
    Initialize an empty result string and its non-error state.
   
</p>
<p> 
    Scan the template and copy literals to the result string (as in
    <a class='info' href='#literal-expansion'>Section&nbsp;3.1<span> (</span><span class='info'>Literal Expansion</span><span>)</span></a>) until an expression is indicated
    by a "{" or the template ends.  When it ends, return the result string
    and its current error or non-error state.
    </p>
<ul class="text">
<li>If an expression is found, scan the template to the next "}"
        and extract the characters in between the braces.
</li>
<li>If the template ends before a "}", then append the "{" and
        extracted characters to the result string and return with
        an error status indicating the expression is malformed.
</li>
</ul><p>
   
</p>
<p>
    Examine the first character of the extracted expression for an operator.
    </p>
<ul class="text">
<li>If the expression ended (i.e., is "{}"), an operator is found that
        is unknown or unimplemented, or the character is not in the
        varchar set (<a class='info' href='#variables'>Section&nbsp;2.3<span> (</span><span class='info'>Variables</span><span>)</span></a>), then
        append "{", the extracted expression, and "}" to the result string,
        remember that the result is in an error state, and then go back to
        scan the remainder of the template.
</li>
<li>If a known and implemented operator is found, store the operator
        and skip to the next character to begin the varspec-list.
</li>
<li>Otherwise, store the operator as NUL (simple string expansion).
</li>
</ul><p>
   
</p>
<p>
    Use the following value table to determine the processing behavior by
    expression type operator.
    The entry for "first" is the string to append to the result first if
    any of the expression's variables are defined.
    The entry for "sep" is the separator to append to the result before
    any second (or subsequent) defined variable expansion.
    The entry for "named" is a boolean for whether or not the expansion
    includes the variable or key name when no explode modifier is given.  
    The entry for "ifemp" is a string to append to the name if its
    corresponding value is empty.
    The entry for "allow" indicates what characters to allow unencoded
    within the value expansion: (U) means any character not in the
    unreserved set will be encoded; (U+R) means any character not in
    the (unreserved / reserved / pct-encoding) set will be encoded; and,
    for both cases, disallowed characters are encoded as UTF-8 (a
    sequence of octets) and then each octet is encoded as a pct-encoded
    triplet.
   
</p><div style='display: table; width: 0; margin-left: 3em; margin-right: auto'><pre>
.------------------------------------------------------------------.
|          NUL     +      .       /       ;      ?      &amp;      #   |
|------------------------------------------------------------------|
| first |  ""     ""     "."     "/"     ";"    "?"    "&amp;"    "#"  |
| sep   |  ","    ","    "."     "/"     ";"    "&amp;"    "&amp;"    ","  |
| named | false  false  false   false   true   true   true   false |
| ifemp |  ""     ""     ""      ""      ""     "="    "="    ""   |
| allow |   U     U+R     U       U       U      U      U     U+R  |
`------------------------------------------------------------------'
</pre></div>
<p>
    With the above table in mind, process the variable-list as follows:
   
</p>
<p>
    For each varspec, extract the varname and optional modifier,
    lookup the value for that variable, and then:
    </p>
<ul class="text">
<li>If the varname is unknown or corresponds to a variable with an
        undefined value (<a class='info' href='#variable-expansion'>Section&nbsp;3.2.1<span> (</span><span class='info'>Variable Expansion</span><span>)</span></a>), then skip to
        the next varspec.
</li>
<li>If this is the first defined variable for this expression, append
        the first string for this expression type to the result string 
        and remember that it has been done.  Otherwise, append the
        sep string to the result string.
</li>
<li>If this variable's value is a string, then:
        
<ul class="text">
<li>if named is true, append the varname to the result string using
            the same encoding process as for literals, and
            
<ul class="text">
<li>if the value is empty, append the ifemp string to the
                result string and skip to the next varspec;
</li>
<li>otherwise, append "=" to the result string.
</li>
</ul>
         
</li>
<li>if a prefix modifier is present and the prefix length is
            less than the value string length in number of Unicode
            characters, append that number of characters from the
            beginning of the value string to the result string, after
            encoding any characters that are not in the allow set, while
            taking care not to split multi-octet or pct-encoded triplet
            characters that represent a single Unicode codepoint;
</li>
<li>otherwise, append the value to the result string after
            encoding any characters that are not in the allow set.
</li>
</ul>
     
</li>
<li>If this variable's value is a list, then:
        
<ul class="text">
<li>if no explode modifier is given, then:
            
<ul class="text">
<li>if named is true, append the varname to the result string
                using the same encoding process as for literals, and
                
<ul class="text">
<li>if the value is empty, append the ifemp string to the
                    result string and skip to the next varspec;
</li>
<li>otherwise, append "=" to the result string; and
</li>
</ul>
             
</li>
<li>append each defined list member to the result string,
                after encoding any characters that are not in the allow set,
                with a comma (",") appended to the result between each
                defined list member.
</li>
</ul>
         
</li>
<li>else if an explode modifier is given, then:
            
<ul class="text">
<li>append each defined list member to the result string,
                after encoding any characters that are not in the allow set,
                with the sep string appended to the result between each
                defined list member.
</li>
</ul>
         
</li>
</ul>
     
</li>
<li>If this variable's value is an associative array or any other form
        of paired (name, value) structure, then:
        
<ul class="text">
<li>if no explode modifier is given, then:
            
<ul class="text">
<li>if named is true, append the varname to the result string
                using the same encoding process as for literals, and
                
<ul class="text">
<li>if the value is empty, append the ifemp string to the
                    result string and skip to the next varspec;
</li>
<li>otherwise, append "=" to the result string; and
</li>
</ul>
             
</li>
<li>append each pair with a defined value to the result string
                as "name,value", after encoding any characters that are not
                in the allow set, with a comma (",") appended to the result
                between each defined pair.
</li>
</ul>
         
</li>
<li>else if an explode modifier is given, then:
            
<ul class="text">
<li>append each pair with a defined value to the result string
                as "name=value", after encoding any characters that are not
                in the allow set, with the sep string appended to the result
                between each defined pair.
</li>
</ul>
         
</li>
</ul>
     
</li>
</ul><p>
    When the variable-list for this expression is exhausted,
    go back to scan the remainder of the template.
   
</p>
<a name="rfc.authors"></a><br /><hr />
<table summary="layout" cellpadding="0" cellspacing="2" class="TOCbug" align="right"><tr><td class="TOCbug"><a href="#toc">&nbsp;TOC&nbsp;</a></td></tr></table>
<h3>Authors' Addresses</h3>
<table width="99%" border="0" cellpadding="0" cellspacing="0">
<tr><td class="author-text">&nbsp;</td>
<td class="author-text">Joe Gregorio</td></tr>
<tr><td class="author-text">&nbsp;</td>
<td class="author-text">Google</td></tr>
<tr><td class="author" align="right">Email:&nbsp;</td>
<td class="author-text">joe@bitworking.org</td></tr>
<tr><td class="author" align="right">URI:&nbsp;</td>
<td class="author-text"><a href="http://bitworking.org/">http://bitworking.org/</a></td></tr>
<tr cellpadding="3"><td>&nbsp;</td><td>&nbsp;</td></tr>
<tr><td class="author-text">&nbsp;</td>
<td class="author-text">Roy T. Fielding</td></tr>
<tr><td class="author-text">&nbsp;</td>
<td class="author-text">Adobe Systems Incorporated</td></tr>
<tr><td class="author" align="right">Email:&nbsp;</td>
<td class="author-text">fielding@gbiv.com</td></tr>
<tr><td class="author" align="right">URI:&nbsp;</td>
<td class="author-text"><a href="http://roy.gbiv.com/">http://roy.gbiv.com/</a></td></tr>
<tr cellpadding="3"><td>&nbsp;</td><td>&nbsp;</td></tr>
<tr><td class="author-text">&nbsp;</td>
<td class="author-text">Marc Hadley</td></tr>
<tr><td class="author-text">&nbsp;</td>
<td class="author-text">The MITRE Corporation</td></tr>
<tr><td class="author" align="right">Email:&nbsp;</td>
<td class="author-text">mhadley@mitre.org</td></tr>
<tr><td class="author" align="right">URI:&nbsp;</td>
<td class="author-text"><a href="http://mitre.org/">http://mitre.org/</a></td></tr>
<tr cellpadding="3"><td>&nbsp;</td><td>&nbsp;</td></tr>
<tr><td class="author-text">&nbsp;</td>
<td class="author-text">Mark Nottingham</td></tr>
<tr><td class="author-text">&nbsp;</td>
<td class="author-text">Rackspace</td></tr>
<tr><td class="author" align="right">Email:&nbsp;</td>
<td class="author-text">mnot@mnot.net</td></tr>
<tr><td class="author" align="right">URI:&nbsp;</td>
<td class="author-text"><a href="http://www.mnot.net/">http://www.mnot.net/</a></td></tr>
<tr cellpadding="3"><td>&nbsp;</td><td>&nbsp;</td></tr>
<tr><td class="author-text">&nbsp;</td>
<td class="author-text">David Orchard</td></tr>
<tr><td class="author-text">&nbsp;</td>
<td class="author-text">Salesforce.com</td></tr>
<tr><td class="author" align="right">URI:&nbsp;</td>
<td class="author-text"><a href="http://www.pacificspirit.com/">http://www.pacificspirit.com/</a></td></tr>
</table>
</body></html>
